<?php
class Macys_Api_V2_Registry {
	
	private $log;
	private $globals;
	private $registryV2Uri;
	private $client;
	
	protected $data;
	
	public function __construct() {
		$this->log = Zend_Registry::get('log');
		$this->globals = new Macys_Base_Globals();
		$this->setupRegistryUrl();
		$this->data = new Macys_Api_V2_Registry_Data();
		$this->client = new Macys_Base_HttpClient();
		$this->client->isProtectedService();
		//$this->client->setClientHeader('7xydgv2mvrqc9nc2mrctjhv8');
		$this->client->setAcceptType();
		
	}
	
	public function createRegistry() {
		$this->client->setRawData($this->data->createRegistry());
		$this->client->setUri($this->registryV2Uri); // Removed on Mashery 
		//$this->client->setUri($this->registryV2Uri . '/create');
		$this->client->setContentTypeJson();
		$this->client->setCurlSupport();
		$this->client->request('POST');
		return $this->client->getResponseBodyArray();
	}
	
	/**
	 * Gets the Users Registry
	 * Enter description here ...
	 */
	public function getRegistry() {
		$this->client->setUri($this->registryV2Uri);
		//$this->client->setUri($this->registryV2Uri . '/create');
		$this->client->setParameterGet('show','basic,bride,groom,shipping,items');
		$this->client->setParameterGet('type', 'BVR');
		$this->client->request();
		return $this->client->getResponseBodyArray();
	}
	
	
	public function addItems($input) {
		$this->client->setRawData($input);
		$this->registryV2Uri = $this->registryV2Uri . '/items';
		$this->client->setUri($this->registryV2Uri);
		$this->client->setContentTypeJson();
		$this->client->setCurlSupport();
		$this->client->request('POST');
		return $this->client->getResponseBodyArray();
		
	}
	
	public function getRegistryById($type = 'GVR') {
		//$user = new Macys_Api_V2_User();
		//$regId = $user->getRegistryId();
		// TODO clear the Get Parameters
		$this->client->resetParameters();
		
		$getById = $this->registryV2Uri . '/by-id/801603'; // . $regId;
		$this->client->setUri($getById);
		
		$this->client->setParameterGet('type', $type);
		$this->client->request();
		return $this->client->getResponseBodyArray();
	}
	
	public function getRegistryByName($firstName=null, $lastName=null,$eventMonth=null, $eventYear=null) {
		
	}
	
	private function setupRegistryUrl() {
		$api = $this->globals->getConfigValues('api');
		$this->registryV2Uri = $api['api_url'] . $api['v2']['registry'];
		$this->log->debug('Registry URL : ' . $this->registryV2Uri);
		
	}
	
}